package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据 父类目id 查询多条数据
     * @param pid
     * @return
     */
    @GetMapping("of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPid(@RequestParam("pid")Long pid) {
        return ResponseEntity.ok(categoryService.queryCategoryByPid(pid));
    }

    /**
     * 根据分类id查询单条数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id")Long id) {

        return ResponseEntity.ok(categoryService.queryCategoryById(id));
    }

    /**
     * 根据分类id的集合,查询商品分类的集合
     * @param ids
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids")Long[] ids) {
        return ResponseEntity.ok(categoryService.queryCategoryByIds(ids));

    }

    /**
     * 根据品牌的id 查询对应的分类集合
     * @param brand_id
     * @return
     */
    @GetMapping("of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrandId(@RequestParam("id")Long brand_id) {

        //categoryService.queryCategoryByBrandId(id);
        return ResponseEntity.ok(categoryService.queryCategoryByBrandId(brand_id));

    }

}
